<?php
namespace Tbf\Error;
/**
 * 会导致 @mkdir 挂掉
 * @deprecated
 */
class ErrorToExceptionHandle extends Handle{
    function handle(){
        set_error_handler(array($this,'errorHandleFunc'));
    }

    function errorHandleFunc($errno, $errstr, $errfile, $errline){
        //编译错误时,不会自动加载类
        $this->tryLoad('Tbf\Util\ErrorUtil');
        $this->tryLoad('Tbf\Error\Exception');
        $this->tryLoad('Tbf\Error\ErrorException');
        $e = new ErrorException(array(
            'message'=>$errstr,
            'level_code'=>$errno,
            'file'=>$errfile,
            'line'=>$errline
            )
        );
        throw $e;
    }
    function tryLoad($class_name){
        if (!class_exists($class_name)){
            spl_autoload_call($class_name);
        }
    }
}
